package com.example.demo.util.httpclient;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;

/**
 * HttpExecutor
 *
 * @author hao.chen
 * @date 2023/6/3 19:54
 */
public class HttpExecutor {

    private final HttpClient httpClient;

    HttpExecutor(final HttpClient httpClient) {
        this.httpClient = httpClient;
    }

    public Executor get(String url) {
        return new Executor(httpClient, new HttpGet(url), BodyType.FORM);
    }

    public Executor post(String url) {
        return new Executor(httpClient, new HttpPost(url), BodyType.FORM);
    }

    public Executor postJson(String url) {
        return new Executor(httpClient, new HttpPost(url), BodyType.JSON);
    }

    public Executor putJson(String url) {
        return new Executor(httpClient, new HttpPut(url), BodyType.JSON);
    }

    public Executor patchJson(String url) {
        return new Executor(httpClient, new HttpPatch(url), BodyType.JSON);
    }

    public Executor postXml(String url) {
        return new Executor(httpClient, new HttpPost(url), BodyType.XML);
    }

    public Executor upload(String url) {
        return new Executor(httpClient, new HttpPost(url), BodyType.FILE);
    }
}
